package x.y;


import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.core.Ordered;
import org.springframework.util.StopWatch;

public class SimpleProfiler implements Ordered {

	private static Logger logger = Logger.getLogger(SimpleProfiler.class);
	
	private int order;

	  // allows us to control the ordering of advice
	  public int getOrder() {
	    return this.order;
	  }

	  public void setOrder(int order) {
	    this.order = order;
	  }

	// this method is the around advice
	  public Object profile(ProceedingJoinPoint call) throws Throwable {
	    Object returnValue;
	    StopWatch clock = new StopWatch(getClass().getName());
	    try {
	      logger.debug("SimpleProfiler开始");
//	      clock.start(call.toShortString());
	      returnValue = call.proceed();
	    } finally {
//	      clock.stop();
//	      logger.debug(clock.prettyPrint());
	      logger.debug("SimpleProfiler结束");
	    }
	    return returnValue;
	  }
}
